<template>
    <div class='fxn-body'>
        <Searchs v-model:searchData="searchData" v-model:SearchForm="SearchForm" @handleSearch="handleSearch"></Searchs>
        <!-- Search End -->
        <div class="fxn-section fixed fxn-margin-t-20">
            <el-table v-loading="loading" :data="listData">
                <el-table-column label="案件名称" prop="title">
                    <template #default="scope">
                        <el-link type="primary" :underline="false" @click="handlePath(scope.row)">{{scope.row.title}}</el-link>
                    </template>
                </el-table-column>
                <el-table-column label="案件状态" prop="status" width="160">
                    <template #default="scope">
                        {{$filter.caseStatus(scope.row.lawcase_status,scope.row.case_type)}}
                    </template>
                </el-table-column>
                <el-table-column label="判决文书" prop="court_verdict" width="160">
                    <template #default="scope">
                        {{$filter.formatData(scope.row.court_verdict,'court_verdict')}}
                    </template>
                </el-table-column>
                <el-table-column label="判决结果" prop="court_result" width="120">
                    <template #default="scope">
                        {{$filter.formatData(scope.row.court_result,'court_result')}}
                    </template>
                </el-table-column>
                <el-table-column label="判决金额" prop="amounts" width="120" />
                <el-table-column label="判决时间" prop="judgment_time" width="120">
                    <template #default="scope">
                        {{$filter.dateTime(scope.row.judgment_time)}}
                    </template>
                </el-table-column>
                <el-table-column label="判决描述" prop="content" />
                <el-table-column label="创建时间" prop="create_time" width="160">
                    <template #default="scope">
                        {{$filter.dateTime(scope.row.create_time,1)}}
                    </template>
                </el-table-column>
                <el-table-column label="创建人" prop="create_with" width="120" />
                <el-table-column label="操作" prop="create_with" width="120">
                    <template #default="scope">
                        <el-link type="primary" :underline="false" @click="handleDetail(scope.row)">查看</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- Section End -->

        <div class="fxn-page fixed">
            <el-pagination v-model:current-page="page" v-model:page-size="perPage" :page-sizes="[10, 50, 100, 200, 500]" layout="total, sizes, prev, pager, next" :total="count" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
        <!-- Page End -->

        <!-- 查看 -->
        <el-dialog title="查看" v-model="detailDialog" width="800">
            <el-descriptions :column="2" border>
                <el-descriptions-item label="案件名称">{{detailData.title}}</el-descriptions-item>
                <el-descriptions-item label="案件状态">{{$filter.caseStatus(detailData.lawcase_status,detailData.case_type)}}</el-descriptions-item>
                <el-descriptions-item label="判决文书">{{$filter.formatData(detailData.court_verdict,'court_verdict')}}</el-descriptions-item>
                <el-descriptions-item label="判决结果">{{$filter.formatData(detailData.court_result,'court_result')}}</el-descriptions-item>
                <el-descriptions-item label="客户满意度">{{$filter.formatData(detailData.customer_feedback,'customer_feedback')}}</el-descriptions-item>
                <el-descriptions-item label="快递单号">{{detailData.express_number}}</el-descriptions-item>
                <el-descriptions-item label="判决时间">{{$filter.dateTime(detailData.judgment_time)}}</el-descriptions-item>
                <el-descriptions-item label="判决金额">{{detailData.amounts}}</el-descriptions-item>
                <el-descriptions-item label="创建人">{{detailData.create_with}}</el-descriptions-item>
                <el-descriptions-item label="创建时间">{{$filter.dateTime(detailData.create_time,1)}}</el-descriptions-item>
            </el-descriptions>
            <el-descriptions :column="1" border>
                <el-descriptions-item label="判决描述">{{detailData.content}}</el-descriptions-item>
                <el-descriptions-item label="附件">
                    <span v-for="(list,key) in detailData.files" :key="key">
                        <i v-if="list.xext == 'jpg' || list.xext == 'png'" class="iconfont icon-picture fxn-ft-24" @click="handleFile(list.xurl)"></i>
                        <i v-if="list.xext == 'pdf'" class="iconfont icon-pdf fxn-ft-24" @click="handleFile(list.xurl)"></i>
                        <i v-if="list.xext == 'docx' || list.xext == 'xlsx' || list.xext == 'pptx'" class="iconfont icon-document fxn-ft-24" @click="handleFile(list.xurl)"></i>
                        <el-icon v-if="list.xext == 'rar' || list.xext == 'zip'" size="24" @click="handleFile(list.xurl)"><Files /></el-icon>
                    </span>
                </el-descriptions-item>
            </el-descriptions>
        </el-dialog>
        <!-- 查看 End -->
    </div>
</template>

<script>
    import Searchs from '../Common/Search.vue'
    import { defineComponent, reactive, getCurrentInstance, onMounted, toRefs, computed } from 'vue'
    import { useRouter } from 'vue-router'
    import { useStore } from 'vuex'
    export default defineComponent({
        components: {Searchs},
        setup() {
            const { proxy } = getCurrentInstance();
            const router = useRouter();
            const store = useStore();

            //初始化数据
            const state = reactive({
                count: 0,
                page: 0,
                perPage: 10,
                loading: false,
                listData: [],

                //搜索
                SearchForm: {
                    title: '',
                    court_verdict: '',
                    judgment_time: '',
                },
                searchData: [
                    {label: '案件名称', prop: 'title', type: 'input'},
                    {label: '判决文书', prop: 'court_verdict', type: 'select', data: computed(() => store.state.configEnable.court_verdict), selectlabel: 'value', selectvalue: 'name'},
                    {label: '判决时间', prop: 'judgment_time', type: 'daterange'},                    
                ],

                //查看
                detailDialog: false,
                detailData: {},
            })

            //列表
            const getList = (page,perPage) => {
                state.loading = true;
                proxy.$http.get('/oa/Lawcase/judgments',{
                    page: page ? page : 1,
                    perPage: perPage ? perPage : 10,
                    title: state.SearchForm.title,
                    court_verdict: state.SearchForm.court_verdict,
                    judgment_time: String(state.SearchForm.judgment_time),
                })
                .then(res=> {
                    state.loading = false;
                    const { code, msg ,data } = res;
                    if(code != 1){
                        return proxy.$msg.error(msg);
                    }else{
                        state.count = data.count;
                        state.page = data.page;
                        state.perPage = data.perPage;
                        state.listData = data.list;
                    }
                })
            }

            //查看
            const handleDetail = (row) => {
                proxy.$http.get('/oa/Lawcase/judgmentForm',{id: row.id})
                .then(res=> {
                    const { code, msg ,data } = res;
                    if(code != 1){
                        return proxy.$msg.error(msg);
                    }else{
                        state.detailData = data;
                        state.detailData.case_type = row.case_type;
                        state.detailData.title = row.title;
                        state.detailDialog = true;
                    }
                })
            }

            //打开附件
            const handleFile = (file) => {
                window.open(file);
            }

            //跳转详情
            const handlePath = (row) => {
                router.push({path: '/CaseDetail', query: {id: row.lawcase_id, type: row.case_type, pathUrl: '/CaseJudgment'}})
            }

            //搜索
            const handleSearch = (e) => {
                state.SearchForm = e;
                getList(1,10);
            }

            //分页
            const handleSizeChange = (val) => {
                state.perPage = val;
                getList(state.page,state.perPage);
            }

            //页码
            const handleCurrentChange = (val) => {
                state.page = val;
                getList(state.page,state.perPage);
            }

            //获取权限
            const authMenu = (value) => {
                let currentRouter = router.currentRoute.value.path;
                let menuArr = (proxy.$public.authMenu(currentRouter).split(','));
                for (let index = 0; index < menuArr.length; index++) {
                    if(value == menuArr[index]){
                        return true
                    }
                }
            }
            
            //Dom加载
            onMounted(()=>{
                authMenu();
                getList();
            })
            
            return {
                ...toRefs(state),
                
                //请求方法
                getList,
                handleFile,
                handleDetail,
                
                //组件方法
                authMenu,
                handlePath,
                handleSearch,
                handleSizeChange,
                handleCurrentChange,
            }

        },
    })
</script>

<style scoped>
    
</style>